package com.bite.lesson2;

public class Demo_03 {
    public static void main(String[] args) throws InterruptedException {
        SumCount sumCount = new SumCount();
        int time = 1_0000;

        long time01 = System.currentTimeMillis();

        Thread thread03 = new Thread(() -> {
            for (int i = 0; i < time; i++) {
                sumCount.sum();
            }
        });
        Thread thread04 = new Thread(() -> {
            for (int i = 0; i < time; i++) {
                sumCount.sum();
            }
        });

        thread03.start();
        thread04.start();

        thread03.join();
        thread04.join();


        long time02 = System.currentTimeMillis();

        System.out.println("结果为 ：" + sumCount.count);
        System.out.println("运行时间为 ：" + (time02 - time01));
    }
}

class SumCount {
    int count = 0;

    public synchronized void sum() {
        count++;
    }
}
